package com.ailanyin.admin.modules.system.service.impl;

import com.ailanyin.admin.modules.system.mapper.SysLogMapper;
import com.ailanyin.admin.modules.system.model.SysLog;
import com.ailanyin.admin.modules.system.service.SysLogService;
import com.ailanyin.common.exception.Asserts;
import com.ailanyin.security.utils.SecurityUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author ailanyin
 * @version 1.0
 * @since 2021/10/28 0028 下午 14:46
 */
@Service
public class SysLogServiceImpl implements SysLogService {

    @Resource
    private SysLogMapper logMapper;

    @Override
    public void insertLog(SysLog sysLog) {
        logMapper.insertLog(sysLog);
    }

    @Override
    public List<SysLog> list(SysLog sysLog) {
        return logMapper.selectByParam(sysLog);
    }

    @Override
    public void cleanLog() {
        checkIsAllow();
        logMapper.deleteBatchIds(null);
    }

    @Override
    public void removeLog(List<String> logIds) {
        checkIsAllow();
        logMapper.deleteBatchIds(logIds);
    }

    private void checkIsAllow() {
        if (!SecurityUtil.getLoginUser().isAdmin()) {
            Asserts.fail("非超管禁止操作！");
        }
    }
}
